package cn.edu.scau.cmi.zenghanxiong.Singleton;

import java.util.HashMap;
import java.util.Map;


public class Marshal {
	private static Map<String, Marshal> marshalMap = new HashMap<>();
    private String name;

    private Marshal(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static Marshal getInstance(String name) {
        Marshal marshal = marshalMap.getOrDefault(name, null);
        if (marshalMap.size() < 10 && marshal == null) {
            marshal = new Marshal(name);
            marshalMap.put(marshal.getName(), marshal);
        }
        return marshal;
    }
}
